package com.hongmeng.web.controller.operater.newsAndVideo;

import java.util.List;

import com.hongmeng.operater.domain.newsAndVideo.entity.QueryVideoInfoEntity;
import com.hongmeng.operater.domain.newsAndVideo.entity.SaveVideoInfoEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hongmeng.common.annotation.Log;
import com.hongmeng.common.core.controller.BaseController;
import com.hongmeng.common.core.domain.AjaxResult;
import com.hongmeng.common.enums.BusinessType;
import com.hongmeng.operater.domain.newsAndVideo.HmVideo;
import com.hongmeng.operater.service.newsAndVideo.IHmVideoService;
import com.hongmeng.common.utils.poi.ExcelUtil;
import com.hongmeng.common.core.page.TableDataInfo;

/**
 * 视频信息Controller
 * 
 * @author hongmeng
 * @date 2020-12-28
 */
@Api("视频信息管理")
@RestController
@RequestMapping("/operater/video")
public class HmVideoController extends BaseController
{
    @Autowired
    private IHmVideoService hmVideoService;

    /**
     * 查询视频信息列表
     */
    @ApiOperation("查询视频信息列表")
    @PreAuthorize("@ss.hasPermi('operater:video:list')")
    @GetMapping("/list")
    public TableDataInfo list(QueryVideoInfoEntity hmVideo)
    {
        startPage();
        List<HmVideo> list = hmVideoService.selectHmVideoList(hmVideo);
        return getDataTable(list);
    }

    /**
     * 导出视频信息列表
     */
    @PreAuthorize("@ss.hasPermi('operater:video:export')")
    @Log(title = "视频信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QueryVideoInfoEntity hmVideo)
    {
        List<HmVideo> list = hmVideoService.selectHmVideoList(hmVideo);
        ExcelUtil<HmVideo> util = new ExcelUtil<HmVideo>(HmVideo.class);
        return util.exportExcel(list, "video");
    }

    /**
     * 获取视频信息
     */
    @ApiOperation("获取视频信息")
    @PreAuthorize("@ss.hasPermi('operater:video:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(hmVideoService.selectHmVideoById(id));
    }

    /**
     * 获取视频信息详情
     */
    @ApiOperation("获取视频信息详情")
    @PreAuthorize("@ss.hasPermi('operater:video:query')")
    @GetMapping(value = "/getDetailedInfo/{id}")
    public AjaxResult getDetailedInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(hmVideoService.selectHmVideoDetailedById(id));
    }

    /**
     * 新增视频信息
     */
    @ApiOperation("新增视频信息")
    @PreAuthorize("@ss.hasPermi('operater:video:add')")
    @Log(title = "视频信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaveVideoInfoEntity hmVideo)
    {
        return hmVideoService.insertHmVideo(hmVideo);
    }

    /**
     * 修改视频信息
     */
    @ApiOperation("修改视频信息")
    @PreAuthorize("@ss.hasPermi('operater:video:edit')")
    @Log(title = "视频信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaveVideoInfoEntity hmVideo)
    {
        return hmVideoService.updateHmVideo(hmVideo);
    }

    /**
     * 删除视频信息
     */
    @PreAuthorize("@ss.hasPermi('operater:video:remove')")
    @Log(title = "视频信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(hmVideoService.deleteHmVideoByIds(ids));
    }

    /**
     * 新建视频文件
     */
    @ApiOperation("新建视频文件")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "视频id(凭证)",name = "videoId",required = true,paramType = "path"),
            @ApiImplicitParam(value = "视频源地址",name = "sourceUrl",paramType = "path")
    })
    @PreAuthorize("@ss.hasPermi('operater:video:add')")
    @PostMapping("/addVideoFiles")
    public AjaxResult saveVideoFiles(String videoId,String sourceUrl) {
        return hmVideoService.saveVideoFiles(videoId,sourceUrl);
    }

    /**
     * 审核视频信息
     */
    @ApiOperation("审核视频信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "视频id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "yesOrNo", value = "审核是否通过(true/false)", required = true, dataType = "boolean"),
            @ApiImplicitParam(name = "newsRemarks", value = "审核备注(通过与不通过的理由)", dataType = "String")
    })
    @PreAuthorize("@ss.hasPermi('operater:news:examine')")
    @PutMapping("/examine")
    public AjaxResult examine(Integer id, boolean yesOrNo, String newsRemarks) {
        return hmVideoService.examine(id, yesOrNo, newsRemarks);
    }
}
